package tazmania;

import tazadum.engine.Engine;
import tazadum.engine.Interval;
import tazadum.engine.Signal;
import tazmania.entity.ColorFanBackgroundEntity;
import tazmania.entity.FadeToWhiteEntity;
import tazmania.entity.HexagonStripEntity;
import tazmania.entity.MetaballsEntity;
import tazmania.entity.ShowTextEntity;
import tazmania.entity.SolidBackgroundEntity;
import tazmania.entity.SquareGrowerEntity;
import tazmania.entity.SupG;
import tazmania.entity.WireframeLandscapeEntity;

public class Tazmania {
	private Engine engine;

	public static void main(final String[] args) {
		final Tazmania tazmania = new Tazmania();
		tazmania.start();
	}

	private void start() {
		final boolean fullscreen = Boolean.parseBoolean(System.getProperty("fullscreen", "false"));
		engine = new Engine("retro", 640, 480, fullscreen);
		final Signal signal = engine.getSignal();

		final ShowTextEntity introText = new ShowTextEntity(signal, Signal.CHANNEL_ZERO);
		introText.addText("edison", 100, new Interval(4, 15.5f));
		introText.addText("2012", 260, new Interval(7, 15.5f));

		final ShowTextEntity demoText = new ShowTextEntity(signal, Signal.CHANNEL_ZERO);
		demoText.addText("retro", 200, new Interval(0, 8f));

		final ShowTextEntity endText = new ShowTextEntity(signal, Signal.CHANNEL_ZERO);
		endText.addText("time for us to sleep", 170, new Interval(0, 16.5f));
		endText.addText(" bysse  druttis ", 250, new Interval(4, 16.9f));
		endText.addText(" nicke  robban ", 320, new Interval(5, 17.3f));
		// endText.addText("period", 355, new Interval(3, 9.0f));

		// 0: tingle
		// 1: kick
		// 2: synth slinga
		// 3: virvel
		// 4: base
		// 5: hihat
		// 6:
		// 7:

		final float lastEffect = 106;
		// engine.activate(endText, new Interval(0, lastEffect), 18);

		final SupG supG = new SupG(signal, Signal.CHANNEL_SYNTH_ENV_4);
		final SquareGrowerEntity growerEntity = new SquareGrowerEntity(signal, Signal.CHANNEL_SYNTH_ENV_2, Signal.CHANNEL_SYNTH_ENV_3);
		final WireframeLandscapeEntity landscapeEntity = new WireframeLandscapeEntity(signal, Signal.CHANNEL_SYNTH_ENV_1,
				Signal.CHANNEL_SYNTH_ENV_3, Signal.CHANNEL_SYNTH_ENV_1);

		engine.activate(new SolidBackgroundEntity(signal), new Interval(0, lastEffect), 0);

		if (true) {
			engine.activate(introText, new Interval(0, 20), 12);
			engine.activate(landscapeEntity, new Interval(0, 50), 10);

			engine.activate(new ColorFanBackgroundEntity(signal), new Interval(21, 49), 1);
			engine.activate(demoText, new Interval(17, 30), 20);
			engine.activate(supG, new Interval(28, 40), 18);

			engine.activate(growerEntity, new Interval(33, 62), 11);

			engine.activate(new HexagonStripEntity(signal), new Interval(49, 85), 10);
			engine.activate(supG, new Interval(50, 71), 18);
		}
		engine.activate(new MetaballsEntity(signal, Signal.CHANNEL_SYNTH_ENV_1), new Interval(81, 101), 11);
		engine.activate(landscapeEntity, new Interval(81, 101), 10);
		engine.activate(endText, new Interval(62, 101), 18);

		engine.activate(new FadeToWhiteEntity(), new Interval(96, 101), 100);

		final ShowTextEntity endText2 = new ShowTextEntity(signal, Signal.CHANNEL_ZERO);
		endText2.addText(" zzzzz ", 250, new Interval(0, 10f));

		engine.activate(endText2, new Interval(97, lastEffect), 120);
		engine.fadeOutSound(lastEffect - 4, 4);
		engine.activate(new FadeToWhiteEntity(), new Interval(lastEffect - 4, lastEffect), 140);

		engine.start();
		System.exit(0);
	}
}
